import { defineConfig,loadEnv} from "vite"
import vue from "@vitejs/plugin-vue"
import { resolve } from "path" // 主要用于alias文件路径别名
import { createHtmlPlugin } from "vite-plugin-html"
import AutoImport from "unplugin-auto-import/vite"
import Components from "unplugin-vue-components/vite"
import { ElementPlusResolver } from "unplugin-vue-components/resolvers"
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import vueSetupExtend from 'vite-plugin-vue-setup-extend' //组件名进行注册的

// https://vitejs.dev/config/
export default defineConfig(({mode})=>{
  const env = loadEnv(mode, __dirname)
  console.log(mode)
  return {
    plugins: [
      vue(),
      vueSetupExtend(),
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
      createSvgIconsPlugin({
        // 指定需要缓存的图标文件夹
        iconDirs: [resolve(process.cwd(), 'src/assets/svg')],
        // 指定symbolId格式
        symbolId: 'icon-[dir]-[name]',
      })
    ],
    server: {                
      host: '0.0.0.0'
    },
    base: './',    
    outDir: 'dist',
    resolve: {
      alias: {
        '@': resolve(__dirname, '.', 'src'),
      },
    },
  }
})
